<template>
  <div class="chat-box-header" @click="toSetting">
    <div class="header-avatar">
      <img class="header-avatar-img" v-if="user.avatar" :src="`http://192.168.137.35:8080/files/${user.avatar}`" alt="avatar" />
    </div>
    <div class="header-info">
      <div class="info-name-status">
        <div class="info-name">{{user.nickname || '未设置'}}</div>
        <div class="info-status">
          <div class="status-dot"></div>
          <div v-if="user.status === 1" class="status-text">在线</div>
          <div v-if="user.status === 2" class="status-text">离线</div>
          <div v-if="user.status === 3" class="status-text">忙碌</div>
        </div>
      </div>
      <div class="info-mood">{{user.message}}</div>
    </div>
  </div>
</template>

<script>
import axios from '../../helper/axios';

export default {
  data() {
    return {
      user: {},
    };
  },
  mounted() {
    axios.get('/api/user/detail').then((res) => {
      this.user = res;
    });
  },
  methods: {
    toSetting() {
      this.$router.push('/info');
    },
  },
};
</script>

<style>
.chat-box-header {
  height: 120px;
  background-color: #979797;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 15px 0 0;
}

.header-avatar {
  height: 80px;
  width: 80px;
  background-color: #f5f5f5;
  border-radius: 10px;
}

.header-avatar-img {
  height: 80px;
  width: 80px;
  border-radius: 10px;
}

.header-info {
  width: 155px;
  margin-left: 15px;
}

.info-name-status {
  display: flex;
  align-items: center;
}

.info-name {
  font-weight: bold;
  font-size: 18px;
  color: #fff;
}

.info-status {
  display: flex;
  align-items: center;
  margin-left: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 5px;
  background-color: rgb(25, 255, 25);
}
.status-text {
  font-size: 12px;
  color: #fff;
  margin-left: 3px;
}

.info-mood {
  color: rgb(218, 218, 218);
  font-size: 12px;
  margin-top: 5px;
  width: 155px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
